< previous page page_401 next page >

Page 401
2. A service is stopped using the ControlService function, which is defined as follows:
7017a6ead0e3c4111b47a554df321e9f.gif
BOOL ControlService(
    SC_HANDLE hService,               // handle to service
    DWORD dwControl,                  // control code
    LPSERVICE_STATUS lpServiceStatus  // pointer to service status structure
   );
The dwControl parameter takes a constant value defined with the prefix SERVICE_ CONTROL_*. For our purposes, you will use the SERVICE_CONTROL_STOP constant to stop the service. The function also loads a SERVICE_STATUS structure.
3. The final service function you will need is the QueryServiceStatus function, which is defined as follows:
7017a6ead0e3c4111b47a554df321e9f.gif
BOOL QueryServiceStatus(
    SC_HANDLE hService,               // handle of service
    LPSERVICE_STATUS lpServiceStatus  // address of service status structure
   );
This function can be used to query the status of a service. You'll use it to find out when a requested operation is complete.
Choosing Objects
We've now completed the first step in the design processgaining familiarity with the underlying objects, data structures, and functions. The order in which I listed items in that sentence is significant. An important part of object-oriented programming is choosing the objects for your design. How do you choose objects? First, there is a good chance that you will have an object that corresponds to objects in the underlying system. We've identified two system objects: the Service Control Manager and the service itself. This suggests two classes, one we'll call ServiceManager, which corresponds to the Service Control Manager, and another called ServiceObject, which corresponds to the service. Each of these classes will contain a private variable to hold the handle to the corresponding system object.
Next, you may have objects that correspond to the data structures you are working with. We've identified two objects, the ENUM_SERVICE_STATUS structure and the SERVICE_STATUS structure. You could create one object for each, but the ENUM_SERVICE_STATUS structure contains the SERVICE_STATUS structure, so this would result in a potentially complex object hierarchy. While

 
< previous page page_401 next page >